/**  
 * @Title: DataXComp.java
 * @Description: TODO(描述)
 * @author liuyi
 * @date 2023-04-13 16:21:25 
 */  
package com.fsxgt.datagrid.component.handler.impl;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.fsxgt.datagrid.component.bo.CmpSyncOfflineBO;
import com.fsxgt.datagrid.component.dao.DataWorkMapper;

import lombok.extern.slf4j.Slf4j;

/**  
 * @ClassName: DataxComponent
 * @Description: TODO(描述)
 * @author liuyi
 * @date 2023-04-13 16:21:25 
*/
@Slf4j
@Component
public class DataWorkHandler extends CmpSyncOfflineHandler{
	
	@Autowired
	private DataWorkMapper dataWorkMapper;


	@Autowired
	private JdbcTemplate jdbcTemplate;

	
	public String getSrcStartId(CmpSyncOfflineBO bo) {
		return dataWorkMapper.get(bo.getId()).getSrcStartId();
	}
	
	
	public void callBack(CmpSyncOfflineBO bo,Object srcMaxValue) {
		String sql="update data_work set src_start_id=? where id=?";
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		if(srcMaxValue instanceof Date ) {
			jdbcTemplate.update(sql, sdf.format(srcMaxValue),bo.getId());
		}else if(srcMaxValue instanceof LocalDateTime ) {
			String srcStartId=((LocalDateTime)srcMaxValue).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
			jdbcTemplate.update(sql,srcStartId,bo.getId());
		}else {
			if(srcMaxValue!=null) {
				jdbcTemplate.update(sql, srcMaxValue.toString(),bo.getId());
			}
		}
	}
	
	@Override
	public String getComponentType() {
		// TODO Auto-generated method stub
		return "Data Work";
	}
	
	
}
